{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class=""><a href="{:url('admin/robot/index')}">机器人管理</a></li>
            <li class="layui-this">添加机器人</li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">
                <form class="layui-form form-container" action="{:url('admin/robot/update')}" method="post">
                    <div class="layui-form-item">
                        <label class="layui-form-label">用户名</label>
                        <div class="layui-input-block">
                            <input type="text" name="username" value="{$user.username}" required lay-verify="required"
                                   placeholder="请输入用户名" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">昵称</label>
                        <div class="layui-input-block">
                            <input type="text" name="user_nick" value="{$user.user_nick}" required lay-verify="required"
                                   placeholder="请输入昵称" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">头像</label>
                        <div class="layui-input-block">
                            <img src="{$user.headimg|default='__STATIC__/images/default_thumb.png'}" id="avatar_img" style="width:50px">
                            <input type="file" name="avatar" class="layui-upload-file">
                            <input type="hidden" name="headimg" value="{$user.headimg}">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <input type="hidden" name="id" value="{$user.id}">
                            <button class="layui-btn" lay-submit lay-filter="*">保存</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="script"}
<script>
    form.on('switch(agent)', function (data) {
        if (data.elem.checked) {
            $('input[name=is_agent]').val(1);
        } else {
            $('input[name=is_agent]').val(0);
        }
        // console.log(data.elem); //得到checkbox原始DOM对象
        // console.log(data.elem.checked); //开关是否开启，true或者false
        // console.log(data.value); //开关value值，也可以通过data.elem.value得到
        // console.log(data.othis); //得到美化后的DOM对象
    });

    layui.upload({
        url: '{:url("admin/robot/upload")}'
        ,success: function(res){
            if(res.code == 0){
                $('#avatar_img').attr('src',res.data.url);
                $('[name=headimg]').val(res.data.url);
            }
        }
    });
</script>
{/block}